package Case;

import java.lang.reflect.Array;
import java.util.Arrays;
public class bubbleSort {
    public static void bubbleSort(int[] array) {

        for (int i = 0; i < array.length - 1; i++) {
            boolean flg = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if (array[j] > array[j + 1]) {
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j+1]=tmp;
                    flg = true;
                }
            }
            if (flg == false) {
                return;
            }
        }
    }
    public static void main(String[] args) {
        int[] array = {1, 2, 33, 7, 99, 5, 36};
        System.out.println("排序前的数组:" + Arrays.toString(array));
        bubbleSort(array);
        System.out.println("排序后的数组:" + Arrays.toString(array));
    }
}

